package com.ybg.service;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ybg.dao.SchoolApply;
import com.ybg.dao.SchoolDao;
import com.ybg.model.ResponseModel;
import com.ybg.utils.YbgException;

/**
 * 学校相关
 * 1、【官网】开通申请service类
 * @author	jade
 * @since	2017年3月31日
 */
@Service
public class SchoolService extends AbstractService {
	@Autowired
	private SchoolDao schoolDao;
	@Autowired
	private SchoolApply schoolApply;
	
	
	/**
	 * 提交【官网】开通申请的表单信息
	 * @param schoolName
	 * @param userName
	 * @param userId
	 * @param mobile
	 * @param qq
	 * @param applyReason
	 * @param email
	 * @param apartment
	 * @return
	 */
	public String officialWebsiteApply(String schoolName, String userName, 
			String userId, String mobile, String qq, String applyReason, String email, String department, String callback){
		String schoolId = UUID.randomUUID().toString();
		boolean flag = schoolApply.officialWebsiteApply(schoolId, schoolName, userName, userId, mobile, qq, applyReason, email, department);
		if(!flag){
			throw new YbgException("0001");
		}
		String toJson = JSON.toJSONString(new ResponseModel(""),SerializerFeature.WriteMapNullValue);
		if (callback == null || "".equals(callback) || callback.isEmpty() || callback.length() <= 0) {
			return toJson;
		} else {
			return callback + "(" + toJson + ")";
		}
		
	}
	
}
